<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="8">
            <a-form-model-item label="职工号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="no">
              <a-input v-model="model.no" placeholder="请输入职工号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tel">
              <a-input v-model="model.tel" placeholder="请输入电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="年龄" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="age">
              <a-input-number v-model="model.age" placeholder="请输入年龄" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="工龄" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="seniority">
              <a-input-number v-model="model.seniority" placeholder="请输入工龄" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="是否满足申请条件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="satisfyRoomCondition">
              <j-dict-select-tag type="list" v-model="model.satisfyRoomCondition" dictCode="yn" placeholder="请选择是否满足申请条件" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="最新得分" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="latestScore">
              <a-input-number v-model="model.latestScore" placeholder="请输入最新得分" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="idcard">
              <a-input v-model="model.idcard" placeholder="请输入身份证号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="身份证人像图" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="idcardFront">
              <j-image-upload isMultiple  v-model="model.idcardFront" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="身份证国徽图" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="idcardBack">
              <j-image-upload isMultiple  v-model="model.idcardBack" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sex">
              <j-dict-select-tag type="list" v-model="model.sex" dictCode="sex" placeholder="请选择性别" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="集团" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gro">
              <a-input v-model="model.gro" placeholder="请输入集团"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="站段" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="station">
              <a-input v-model="model.station" placeholder="请输入站段"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="车间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shop">
              <a-input v-model="model.shop" placeholder="请输入车间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="户口所在地" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="household">
              <a-input v-model="model.household" placeholder="请输入户口所在地"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="家庭地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="address">
              <a-input v-model="model.address" placeholder="请输入家庭地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="是否结婚" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ismarried">
              <j-dict-select-tag type="list" v-model="model.ismarried" dictCode="yn" placeholder="请选择是否结婚" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="配偶姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sname">
              <a-input v-model="model.sname" placeholder="请输入配偶姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="配偶身份证" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sidcard">
              <a-input v-model="model.sidcard" placeholder="请输入配偶身份证"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="配偶工作单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sworkCompany">
              <a-input v-model="model.sworkCompany" placeholder="请输入配偶工作单位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="配偶工作地" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="swordPlace">
              <a-input v-model="model.swordPlace" placeholder="请输入配偶工作地"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="配偶户口所在地" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shousehold">
              <a-input v-model="model.shousehold" placeholder="请输入配偶户口所在地"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="岗位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jobName">
              <a-input v-model="model.jobName" placeholder="请输入岗位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="职称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jobTitle">
              <a-input v-model="model.jobTitle" placeholder="请输入职称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="职位级别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jobLevel">
              <a-input v-model="model.jobLevel" placeholder="请输入职位级别"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="账号状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="state">
              <j-dict-select-tag type="list" v-model="model.state" dictCode="user_status" placeholder="请选择账号状态" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ZnzfEmployeeForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           name: [
              { required: true, message: '请输入姓名!'},
           ],
           sex: [
              { required: true, message: '请输入性别!'},
           ],
           ismarried: [
              { required: true, message: '请输入是否结婚!'},
           ],
        },
        url: {
          add: "/base/znzfEmployee/add",
          edit: "/base/znzfEmployee/edit",
          queryById: "/base/znzfEmployee/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>